Add `template.icon` for setting a custom icon for each feed

Akinori MUSHA 9 years ago
parent
commit
f7e48d7b0e
2 changed files with 23 additions and 1 deletions
  1. 5 0
      app/models/agents/data_output_agent.rb
  2. 18 1
      spec/models/agents/data_output_agent_spec.rb

+ 5 - 0
app/models/agents/data_output_agent.rb

@@ -117,6 +117,10 @@ module Agents
117 117
                                     format: options[:format])
118 118
     end
119 119
 
120
+    def feed_icon
121
+      interpolated['template']['icon'].presence || feed_link + '/favicon.ico'
122
+    end
123
+
120 124
     def feed_description
121 125
       interpolated['template']['description'].presence || "A feed of Events received by the '#{name}' Huginn Agent"
122 126
     end
@@ -166,6 +170,7 @@ module Agents
166 170
             <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
167 171
             <channel>
168 172
              <atom:link href=#{feed_url(secret: params['secret'], format: :xml).encode(xml: :attr)} rel="self" type="application/rss+xml" />
173
+             <atom:icon>#{feed_icon.encode(xml: :text)}</atom:icon>
169 174
              <title>#{feed_title.encode(xml: :text)}</title>
170 175
              <description>#{feed_description.encode(xml: :text)}</description>
171 176
              <link>#{feed_link.encode(xml: :text)}</link>

+ 18 - 1
spec/models/agents/data_output_agent_spec.rb

@@ -133,6 +133,7 @@ describe Agents::DataOutputAgent do
133 133
           <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
134 134
           <channel>
135 135
            <atom:link href="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
136
+           <atom:icon>https://yoursite.com/favicon.ico</atom:icon>
136 137
            <title>XKCD comics as a feed</title>
137 138
            <description>This is a feed of recent XKCD comics, generated by Huginn</description>
138 139
            <link>https://yoursite.com</link>
@@ -229,6 +230,21 @@ describe Agents::DataOutputAgent do
229 230
           expect(content['title']).to eq('XKCD comics as a feed (XKCD)')
230 231
         end
231 232
       end
233
+
234
+      describe "with a specified icon" do
235
+        before do
236
+          agent.options['template']['icon'] = 'https://somesite.com/icon.png'
237
+          agent.save!
238
+        end
239
+
240
+        it "can output RSS" do
241
+          stub(agent).feed_link { "https://yoursite.com" }
242
+          content, status, content_type = agent.receive_web_request({ 'secret' => 'secret1' }, 'get', 'text/xml')
243
+          expect(status).to eq(200)
244
+          expect(content_type).to eq('text/xml')
245
+          expect(Nokogiri(content).at('/rss/channel/atom:icon/text()').text).to eq('https://somesite.com/icon.png')
246
+        end
247
+      end
232 248
     end
233 249
 
234 250
     describe "outputting nesting" do
@@ -329,7 +345,8 @@ describe Agents::DataOutputAgent do
329 345
           <?xml version="1.0" encoding="UTF-8" ?>
330 346
           <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
331 347
           <channel>
332
-           <atom:linkhref="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
348
+           <atom:link href="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
349
+           <atom:icon>https://yoursite.com/favicon.ico</atom:icon>
333 350
            <title>XKCD comics as a feed</title>
334 351
            <description>This is a feed of recent XKCD comics, generated by Huginn</description>
335 352
            <link>https://yoursite.com</link>